/*
 * Copyright 2010 Shumpei Shiraishi
 */
package net.fivegoods.entity.impl.slim3;


@javax.ws.rs.Path("/missions")
@org.slim3.datastore.Model
@javax.persistence.Entity
@javax.xml.bind.annotation.XmlAccessorType(javax.xml.bind.annotation.XmlAccessType.NONE)
@javax.xml.bind.annotation.XmlRootElement
@javax.annotation.Generated("momo.annotation.processing.MomoProcessor")
public class MissionModel implements java.io.Serializable {
	private static final long serialVersionUID = 1L;
	
	@com.google.inject.Inject
	static javax.validation.Validator validator;
	
	@javax.ws.rs.Path("/{key}")
	@javax.ws.rs.GET
	public static net.fivegoods.entity.impl.slim3.MissionModel getByKeyString(
		@javax.ws.rs.PathParam("key") java.lang.String keyStr) {
		return getByKey(com.google.appengine.api.datastore.KeyFactory.stringToKey(keyStr));
	}
	
	public static net.fivegoods.entity.impl.slim3.MissionModel getByKey(com.google.appengine.api.datastore.Key key) {
		return org.slim3.datastore.Datastore.getOrNull(net.fivegoods.entity.impl.slim3.MissionModel.class, key);
	}
	@javax.ws.rs.Path("/{key}")
	@javax.ws.rs.DELETE
	public static void deleteByKeyString(
		@javax.ws.rs.PathParam("key") java.lang.String keyStr) {
		deleteByKey(com.google.appengine.api.datastore.KeyFactory.stringToKey(keyStr));
	}
	public static void deleteByKey(com.google.appengine.api.datastore.Key key) {
		org.slim3.datastore.Datastore.delete(key);
	}


	@javax.ws.rs.GET
	public static java.util.List<net.fivegoods.entity.impl.slim3.MissionModel> query(
		@javax.ws.rs.QueryParam("place") java.lang.String place,
		@javax.ws.rs.DefaultValue("EQUAL") @javax.ws.rs.QueryParam("placeOp") java.lang.String placeOp,
		@javax.ws.rs.QueryParam("description") com.google.appengine.api.datastore.Text description,
		@javax.ws.rs.DefaultValue("EQUAL") @javax.ws.rs.QueryParam("descriptionOp") java.lang.String descriptionOp,
		@javax.ws.rs.QueryParam("category") java.lang.Integer category,
		@javax.ws.rs.DefaultValue("EQUAL") @javax.ws.rs.QueryParam("categoryOp") java.lang.String categoryOp,
		@javax.ws.rs.QueryParam("start") java.util.Date start,
		@javax.ws.rs.DefaultValue("EQUAL") @javax.ws.rs.QueryParam("startOp") java.lang.String startOp,
		@javax.ws.rs.QueryParam("end") java.util.Date end,
		@javax.ws.rs.DefaultValue("EQUAL") @javax.ws.rs.QueryParam("endOp") java.lang.String endOp,
		@javax.ws.rs.QueryParam("entryDeadline") java.util.Date entryDeadline,
		@javax.ws.rs.DefaultValue("EQUAL") @javax.ws.rs.QueryParam("entryDeadlineOp") java.lang.String entryDeadlineOp,
		@javax.ws.rs.QueryParam("fixedNumber") java.lang.Integer fixedNumber,
		@javax.ws.rs.DefaultValue("EQUAL") @javax.ws.rs.QueryParam("fixedNumberOp") java.lang.String fixedNumberOp,
		@javax.ws.rs.QueryParam("clientKey") java.lang.String clientKey,
		@javax.ws.rs.DefaultValue("EQUAL") @javax.ws.rs.QueryParam("clientKeyOp") java.lang.String clientKeyOp,
		@javax.ws.rs.QueryParam("sort") java.util.List<momo.slim3.SortParam> sortParams) {
		org.slim3.datastore.ModelQuery<MissionModel> _query_ = org.slim3.datastore.Datastore.query(MissionModel.class);
		if (placeOp.equals("IS_NULL")) {
			_query_.filter("place", com.google.appengine.api.datastore.Query.FilterOperator.EQUAL, null);
		} else if (place != null) {
			_query_.filter("place", com.google.appengine.api.datastore.Query.FilterOperator.valueOf(placeOp), place);
		}
		if (descriptionOp.equals("IS_NULL")) {
			_query_.filter("description", com.google.appengine.api.datastore.Query.FilterOperator.EQUAL, null);
		} else if (description != null) {
			_query_.filter("description", com.google.appengine.api.datastore.Query.FilterOperator.valueOf(descriptionOp), description);
		}
		if (categoryOp.equals("IS_NULL")) {
			_query_.filter("category", com.google.appengine.api.datastore.Query.FilterOperator.EQUAL, null);
		} else if (category != null) {
			_query_.filter("category", com.google.appengine.api.datastore.Query.FilterOperator.valueOf(categoryOp), category);
		}
		if (startOp.equals("IS_NULL")) {
			_query_.filter("start", com.google.appengine.api.datastore.Query.FilterOperator.EQUAL, null);
		} else if (start != null) {
			_query_.filter("start", com.google.appengine.api.datastore.Query.FilterOperator.valueOf(startOp), start);
		}
		if (endOp.equals("IS_NULL")) {
			_query_.filter("end", com.google.appengine.api.datastore.Query.FilterOperator.EQUAL, null);
		} else if (end != null) {
			_query_.filter("end", com.google.appengine.api.datastore.Query.FilterOperator.valueOf(endOp), end);
		}
		if (entryDeadlineOp.equals("IS_NULL")) {
			_query_.filter("entryDeadline", com.google.appengine.api.datastore.Query.FilterOperator.EQUAL, null);
		} else if (entryDeadline != null) {
			_query_.filter("entryDeadline", com.google.appengine.api.datastore.Query.FilterOperator.valueOf(entryDeadlineOp), entryDeadline);
		}
		if (fixedNumberOp.equals("IS_NULL")) {
			_query_.filter("fixedNumber", com.google.appengine.api.datastore.Query.FilterOperator.EQUAL, null);
		} else if (fixedNumber != null) {
			_query_.filter("fixedNumber", com.google.appengine.api.datastore.Query.FilterOperator.valueOf(fixedNumberOp), fixedNumber);
		}
		if (clientKeyOp.equals("IS_NULL")) {
			_query_.filter("clientKey", com.google.appengine.api.datastore.Query.FilterOperator.EQUAL, null);
		} else if (clientKey != null) {
			_query_.filter("clientKey", com.google.appengine.api.datastore.Query.FilterOperator.valueOf(clientKeyOp), com.google.appengine.api.datastore.KeyFactory.stringToKey(clientKey));
		}
		for (momo.slim3.SortParam _sort_ : sortParams) {
			_query_.sort(_sort_.getProperty(),
				_sort_.isAsc() ?
					com.google.appengine.api.datastore.Query.SortDirection.ASCENDING :
					com.google.appengine.api.datastore.Query.SortDirection.DESCENDING);
		}
		return _query_.asList();
	}

	public MissionModel() {
	}

	private static final String STATIC_KEY_NAME = "STATIC_KEY_NAME";
	public MissionModel(com.google.appengine.api.datastore.Key missionClientKey) {
		this.key = org.slim3.datastore.Datastore.createKey(missionClientKey, this.getClass(), STATIC_KEY_NAME);
	}

	@org.slim3.datastore.Attribute(primaryKey = true)
	private com.google.appengine.api.datastore.Key key;

	public com.google.appengine.api.datastore.Key getKey() {
		return key;
	}
	@javax.xml.bind.annotation.XmlElement
	public java.lang.String getKeyString() {
		return com.google.appengine.api.datastore.KeyFactory.keyToString(key);
	}
	public void setKey(com.google.appengine.api.datastore.Key key) {
		this.key = key;
	}




	@org.slim3.datastore.Attribute	
@javax.ws.rs.FormParam("place")
	private java.lang.String place;
	
	public void setPlace(java.lang.String place) {
		this.place = place;
	}
	@javax.xml.bind.annotation.XmlElement
	public java.lang.String getPlace() {
		return this.place;
	}

	@org.slim3.datastore.Attribute	
@javax.ws.rs.FormParam("description")
	private com.google.appengine.api.datastore.Text description;
	
	public void setDescription(com.google.appengine.api.datastore.Text description) {
		this.description = description;
	}
	@javax.xml.bind.annotation.XmlElement
	public com.google.appengine.api.datastore.Text getDescription() {
		return this.description;
	}

	@org.slim3.datastore.Attribute	
@javax.ws.rs.FormParam("category")
	private java.lang.Integer category;
	
	public void setCategory(java.lang.Integer category) {
		this.category = category;
	}
	@javax.xml.bind.annotation.XmlElement
	public java.lang.Integer getCategory() {
		return this.category;
	}

	@org.slim3.datastore.Attribute	
@javax.ws.rs.FormParam("start")
	private java.util.Date start;
	
	public void setStart(java.util.Date start) {
		this.start = start;
	}
	@javax.xml.bind.annotation.XmlElement
	public java.util.Date getStart() {
		return this.start;
	}

	@org.slim3.datastore.Attribute	
@javax.ws.rs.FormParam("end")
	private java.util.Date end;
	
	public void setEnd(java.util.Date end) {
		this.end = end;
	}
	@javax.xml.bind.annotation.XmlElement
	public java.util.Date getEnd() {
		return this.end;
	}

	@org.slim3.datastore.Attribute	
@javax.ws.rs.FormParam("entryDeadline")
	private java.util.Date entryDeadline;
	
	public void setEntryDeadline(java.util.Date entryDeadline) {
		this.entryDeadline = entryDeadline;
	}
	@javax.xml.bind.annotation.XmlElement
	public java.util.Date getEntryDeadline() {
		return this.entryDeadline;
	}

	@org.slim3.datastore.Attribute	
@javax.ws.rs.FormParam("fixedNumber")
	private java.lang.Integer fixedNumber;
	
	public void setFixedNumber(java.lang.Integer fixedNumber) {
		this.fixedNumber = fixedNumber;
	}
	@javax.xml.bind.annotation.XmlElement
	public java.lang.Integer getFixedNumber() {
		return this.fixedNumber;
	}

	private final org.slim3.datastore.ModelRef<net.fivegoods.entity.impl.slim3.MissionClientModel> clientRef = new org.slim3.datastore.ModelRef<net.fivegoods.entity.impl.slim3.MissionClientModel>(net.fivegoods.entity.impl.slim3.MissionClientModel.class);

	public org.slim3.datastore.ModelRef<net.fivegoods.entity.impl.slim3.MissionClientModel> getClientRef() {
		return this.clientRef;
	}

	@org.slim3.datastore.Attribute(persistent=false)
	private final org.slim3.datastore.InverseModelListRef<net.fivegoods.entity.impl.slim3.MissionExecutionModel, net.fivegoods.entity.impl.slim3.MissionModel> executionsRef =
		new org.slim3.datastore.InverseModelListRef<net.fivegoods.entity.impl.slim3.MissionExecutionModel, net.fivegoods.entity.impl.slim3.MissionModel>(net.fivegoods.entity.impl.slim3.MissionExecutionModel.class, "missionRef", this);

	public org.slim3.datastore.InverseModelListRef<net.fivegoods.entity.impl.slim3.MissionExecutionModel, net.fivegoods.entity.impl.slim3.MissionModel> getExecutionsRef() {
		return this.executionsRef;
	}


	@javax.ws.rs.POST
	public void save() {
		if (this.key != null) {
			throw new java.lang.IllegalStateException("key is not null.");
		}
		if (this.validator != null) {
			java.util.Set<javax.validation.ConstraintViolation<MissionModel>> violations = validator.validate(this);
			if (!violations.isEmpty()) {
				throw new javax.validation.ConstraintViolationException(new java.util.HashSet<javax.validation.ConstraintViolation<?>>(violations));
			}
		}
		org.slim3.datastore.Datastore.put(this);
	}
	@javax.ws.rs.Path("/{key}")
	@javax.ws.rs.PUT
	public void save(@javax.ws.rs.PathParam("key") java.lang.String keyStr) {
		this.key = com.google.appengine.api.datastore.KeyFactory.stringToKey(keyStr);
		if (this.validator != null) {
			java.util.Set<javax.validation.ConstraintViolation<MissionModel>> violations = validator.validate(this);
			if (!violations.isEmpty()) {
				throw new javax.validation.ConstraintViolationException(new java.util.HashSet<javax.validation.ConstraintViolation<?>>(violations));
			}
		}
		org.slim3.datastore.Datastore.put(this);
	}
	
	public void delete() {
		if (this.key != null) {
			deleteByKey(this.key);
		}
	}
}
